﻿@using System.Collections
@using Ornament.MemberShip
@using Ornament.Messages
@using Ornament.Web
@model Ornament.MVCWebFrame.Areas.MemberShips.Models.PermissionWizard
@{
    ViewBag.Title = "InfoTypeChoice";
}
@functions {

    private void Build(IEnumerable<InfoType> childNodes)
    {
        var dao = OrnamentContext.Current.GetDaoFactory<IMemberShipFactory>().CreateResourceDao();

        foreach (var node in childNodes)
        {
            var attChecked = this.Model.ResourceId.ToLower() == node.Id.ToString().ToLower() ? "checked='checked'" : "";
            if (node.Count == 0)
            {
                ViewContext.Writer.Write(String.Format(("<li><input type='radio' name='ResourceId' value='{0}' id='{0}' title='{2}' {3}/><label for='{0}'>{1}</label></li>"), node.Id.ToString(), node.Name, node.Remark, attChecked));
            }
            else
            {
                ViewContext.Writer.Write(String.Format(("<li><input type='radio' value='{0}' id='{0}' name='ResourceId' title='{2}' {3}/><label for='{0}'>{1}</label>"), node.Id.ToString(), node.Name, node.Remark, attChecked));
                ViewContext.Writer.Write("<ul>");
                this.Build(node.GetChilds());
                ViewContext.Writer.Write("</ul>");
                ViewContext.Writer.Write("</li>");
            }
        }
    }
}
@{
    IEnumerable<InfoType> infoTypes = OrnamentContext.Current.GetDaoFactory<InfoManager>().Factory.InfoTypeDao.GetFirstLevel();
}

<ul>
    @{
        Build(infoTypes);
    }
</ul>
